home *** CD-ROM | disk | FTP | other *** search
- property objectSprite, objectWidth, objectHeight, solvedLoc, homeLoc, mouseOffset, mouseIsDown, mouseIn, pieceIsSolved, sendsEvent, puzzleGod, cursorGod, infoBox, pieceIn, pieceDropped, solvedLocs, rightMember, leftMember, pieceType, snappy, boardList
-
- on mouseEvent me, xEvent, xLoc
- if pieceIsSolved then
- case xEvent of
- #mouseEnter:
- pointCursor(cursorGod)
- #mouseLeave:
- plainCursor(cursorGod)
- #mouseDown:
- newActivePiece(puzzleGod, me)
- #mouseGone:
- plainCursor(cursorGod)
- end case
- else
- case xEvent of
- #mouseEnter:
- if pieceDropped then
- pointCursor(cursorGod)
- end if
- #mouseDown:
- set pieceDropped to 0
- grabCursor(cursorGod)
- set mouseIsDown to 1
- set mouseOffset to xLoc - the loc of sprite objectSprite
- newActivePiece(puzzleGod, me)
- #mouseDrag:
- movePiece(me, xLoc - mouseOffset)
- set mouseIsDown to 1
- #mouseUp:
- pointCursor(cursorGod)
- dropPiece(me, xLoc - mouseOffset)
- set mouseIsDown to 0
- #mouseGone:
- plainCursor(cursorGod)
- set mouseIsDown to 0
- if not pieceDropped then
- dropPiece(me, xLoc - mouseOffset)
- end if
- end case
- end if
- end
-
- on areYouThere me, xLoc
- set returnThis to inside(xLoc, the rect of sprite objectSprite)
- return returnThis
- end
-
- on highlight me
- if not pieceIsSolved then
- set the blend of sprite objectSprite to 100
- end if
- catchEvent(infoBox, sendsEvent)
- end
-
- on unHighlight me
- if not pieceIsSolved then
- set the blend of sprite objectSprite to 60
- end if
- end
-
- on rightView me
- set the member of sprite objectSprite to rightMember
- updateStage()
- end
-
- on leftView me
- set the member of sprite objectSprite to leftMember
- updateStage()
- end
-
- on getType me
- return pieceType
- end
-
- on getSprite me
- return objectSprite
- end
-
- on new me, xSprite, xType, xSolved, xBoardList
- set objectSprite to xSprite
- set objectWidth to the width of sprite objectSprite
- set objectHeight to the height of sprite objectSprite
- set homeLoc to the loc of sprite objectSprite
- set solvedLocs to xSolved
- set snappy to point(50, 10)
- set boardList to xBoardList
- set pieceType to xType
- set leftMember to member (string(pieceType) && "left")
- set rightMember to member (string(pieceType) && "right")
- set pieceIsSolved to 0
- set pieceIn to 0
- set mouseIn to 0
- puppetSprite(objectSprite, 1)
- set pieceDropped to 1
- return me
- end
-
- on linkUp me, xPuzzleGod, xInfoBox
- set puzzleGod to xPuzzleGod
- set infoBox to xInfoBox
- set sendsEvent to addThing(infoBox, me)
- unsolved(me)
- end
-
- on subscribe me, xCursor
- if cursorGod = 0 then
- nothing()
- else
- unsubscribe(cursorGod, me)
- end if
- set cursorGod to xCursor
- subscribe(cursorGod, me)
- end
-
- on unsubscribe me
- if cursorGod = 0 then
- nothing()
- else
- unsubscribe(cursorGod, me)
- end if
- end
-
- on destroy me
- unsubscribe(me)
- puppetSprite(objectSprite, 0)
- set me to 0
- end
-
- on movePiece me, xLoc
- set the loc of sprite objectSprite to xLoc
- if inside(xLoc, the rightRect of boardList) then
- leftView(me)
- else
- if inside(xLoc, the leftRect of boardList) then
- rightView(me)
- end if
- end if
- end
-
- on dropPiece me, xLoc
- set pieceDropped to 1
- set newLoc to xLoc
- set itsIn to 0
- repeat with i in solvedLocs
- if inside(newLoc, rect(i - snappy, i + snappy)) then
- set itsIn to 1
- set solvedLoc to i
- deleteOne(solvedLocs, i)
- exit repeat
- end if
- end repeat
- if itsIn then
- set newPieceIn to 1
- set newLoc to solvedLoc
- solved(me)
- else
- unsolved(me)
- if newLoc <> homeLoc then
- wrongSound(puzzleGod)
- end if
- set newPieceIn to 0
- set newLoc to homeLoc
- end if
- movePiece(me, newLoc)
- updateStage()
- if newPieceIn <> pieceIn then
- set pieceIn to newPieceIn
- if pieceIn then
- pieceAdded(puzzleGod)
- else
- pieceRemoved(puzzleGod)
- end if
- end if
- end
-
- on solved me
- if not pieceIsSolved then
- pieceSolved(puzzleGod)
- set pieceIsSolved to 1
- end if
- end
-
- on unsolved me
- if pieceIsSolved then
- pieceUnsolved(puzzleGod)
- set pieceIsSolved to 0
- end if
- end
-